package com.miguo.utils;

import android.graphics.Bitmap;
import android.view.View;

import com.miguo.ui.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;

public class Options {

    public static DisplayImageOptions getDefaultOptions() {
        return new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.load_default)
                .showImageForEmptyUri(R.drawable.load_click_310)
                .showImageOnFail(R.drawable.load_failed)
                .bitmapConfig(Bitmap.Config.ARGB_8888)
                .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .build();
    }

    public static DisplayImageOptions getGoodsRoundedOptions() {
        return new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.load_default)
                .showImageForEmptyUri(R.drawable.load_click_310)
                .showImageOnFail(R.drawable.load_failed)
                .bitmapConfig(Bitmap.Config.ARGB_8888)
                .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
                        //.displayer(new FadeInBitmapDisplayer(500))
                .displayer(new RoundedBitmapDisplayer(8))
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .build();
    }

    public static DisplayImageOptions getFadeOptions() {
        return new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.load_default)
                .showImageForEmptyUri(R.drawable.load_click_310)
                .showImageOnFail(R.drawable.load_failed)
                .bitmapConfig(Bitmap.Config.ARGB_8888)
                .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
                        //.displayer(new FadeInBitmapDisplayer(500))
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .build();
    }

    public static DisplayImageOptions getRoundedOptions() {
        return new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.ic_m_default)
                .showImageForEmptyUri(R.drawable.ic_m_default)
                .showImageOnFail(R.drawable.ic_m_default)
                .bitmapConfig(Bitmap.Config.ARGB_8888)
                .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
                        //.displayer(new FadeInBitmapDisplayer(500))
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .build();
    }

    public static DisplayImageOptions getPromotionOptions() {
        return new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.load_default)
                .showImageForEmptyUri(R.drawable.load_default)
                .showImageOnFail(R.drawable.load_default)
                .bitmapConfig(Bitmap.Config.ARGB_8888)
                .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
                        //.displayer(new FadeInBitmapDisplayer(500))
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .build();
    }

    public static DisplayImageOptions getFullScreenOptions() {
        return new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.welcome)
                .showImageForEmptyUri(R.drawable.welcome)
                .showImageOnFail(R.drawable.welcome)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
                        //.displayer(new FadeInBitmapDisplayer(500))
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .build();
    }

    private static class AnimateFirstDisplayListener extends SimpleImageLoadingListener {

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            FadeInBitmapDisplayer.animate(view, 500);
        }
    }

}
